#! /usr/bin/env python
#coding=utf-8
import time,re,ctypes
import os,sys,subprocess,win32gui,win32con,win32api
import glob,time, datetime

ISOTIMEFORMAT='%Y-%m-%d %X'


def createProcess(cmd, wait = False):
 if wait:
  proc = tryExcept(subprocess.Popen, cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
 else:
  proc = tryExcept(subprocess.Popen, cmd)
 if isExcept(proc):
  return
 if not wait:
  return proc.pid
 proc.communicate()

def tryExcept(func, *params, **paramMap):
 try:
  return func(*params, **paramMap)
 except Exception, e:
  return e
def isExcept(e, eType = Exception):
 return isinstance(e, eType)

def killProcessByNames(pnameList, user = None):
 cmd = 'taskkill /F /T'
 if user:
  cmd += ' /FI "USERNAME eq %s"' % user
 for pname in pnameList:
  cmd += ' /IM %s' % pname
  createProcess(cmd, True)


process_name_lst = ['Rtvscan.exe','notepad.exe']
while(1):
 killProcessByNames( process_name_lst ,None)
 print time.strftime( ISOTIMEFORMAT, time.localtime() )
 time.sleep(60)